package com.gitee.wsl.common.ui.base

import androidx.compose.ui.geometry.Size
import androidx.compose.ui.unit.IntSize
import kotlin.math.abs
import kotlin.math.ceil
import kotlin.math.cos
import kotlin.math.sin

/*open class Size(var width:Float = 0f, var height:Float = 0f) {

    override fun toString(): String {
        return "$width x $height"
    }


}*/

/**
 * Returns a recyclable Size instance.
 * Represents size of a rotated rectangle by radians.
 *
 * @param radians
 * @return A Recyclable Size instance
 */
fun Size.getSizeOfRotatedRectangleByRadians(
    radians: Float
): Size {
    return Size(abs(width * cos(radians)) + abs(height * sin(radians)),
        abs(width * sin(radians)) + abs(height * cos(radians))
    )
}

fun Size.toIntSize()= IntSize(ceil(width).toInt(), ceil(height).toInt())

operator fun Size.plus(value: Float): Size  = Size(width + value, height + value)
operator fun Size.minus(value: Float): Size = Size(width - value, height - value)
operator fun Size.rem(value: Float): Size   = Size(width % value, height % value)
operator fun Size.plus(size: Size): Size     = Size(width + size.width, height + size.height)
operator fun Size.minus(size: Size): Size    = Size(width - size.width, height - size.height)
operator fun Size.times(size: Size): Size    = Size(width * size.width, height * size.height)
operator fun Size.div(size: Size): Size      = Size(width / size.width, height / size.height)
operator fun Size.rem(size: Size): Size      = Size(width % size.width, height % size.height)


/**
 * Indicates a class that has a width and a height. Adds a size property to
 * set and get width and height in a single line.
 */
 interface HasSize {

     var width: Float
     var height: Float

     var size:Size
        get() = Size(width, height)
        set(value) {
            width = value.width
            height = value.height
        }
}